package com.company;
import static java.lang.Math.*; //静态导入  无需使用Math
import java.nio.file.Paths; //file 操作
import java.io.*;  //console
import java.time.*; //Date
import java.util.*; //包含Scanner
public class Main {
    public final int I_LOVE_YOU = 520;
    enum Day {M, T, W, TH, F};
    public static strictfp void  main(String[] args) throws IOException{ //strictfp 严格的浮点计算
	// write your code here
        System.out.println("hello word!");


        People zl = new People("zl",18);
        People xj = new People("xj",18);
        zl.sayHello(xj.getName());
        xj.sayHello(zl.getName());

    //--数据类型 8中基础类型
        byte b1 = 34; //1byte -128-127
        short s1 = 0b1001; //2 byte
        int i1 = 2323; //4 byte
        long l1 = 234523l; //8 byte

        float f1 = 3.2f;
        double d1 = 435.34;

        double dd = Double.POSITIVE_INFINITY; //正无穷
        double ddn = Double.NEGATIVE_INFINITY; //负无穷
        if(Double.isNaN(dd)) { //判断dd是否为数值
            System.out.println("dd is not number");
        }

        char c1 = 'q';
        boolean bb1 =false;
        final double PI = 3.123; //常量

        double f11 = Math.sqrt(f1);
        System.out.println(f11);
        System.out.println(Math.pow(f1,2));
        System.out.println(sqrt(PI)); //import static java.Math.*;
        System.out.println(round(5.65));

        Day day = Day.F; //枚举
        String str = "hello!";
        System.out.println(str.substring(0,3));
        String str1 = "hellO!";
        System.out.println(str.equals(str1));
        System.out.println(str.equalsIgnoreCase(str1));
        System.out.println(str.isEmpty());
        System.out.println(str != null && str != "");
        for(int i = 0; i < str.length(); i ++)
            System.out.println(str.charAt(i));
//StringBuilder
        StringBuilder builder = new StringBuilder();
        builder.append("sdf");
        builder.append(34);
        builder.insert(2,"iii");
        System.out.println(builder.toString());


//标准输入输出
        Scanner in = new Scanner(System.in);
        System.out.println("input str:");

        String strIn = in.next(); //接受字符串
        System.out.println("input int:");
        int age = in.nextInt(); //接受int
        System.out.println("input double:");
        double mo = in.nextDouble(); //接受int
 //       System.out.println("循环输入：");
//        while(in.hasNext() )
//        {
//            String strT = in.next();
//            if( strT.equals("")) break;
//            else
//                System.out.println(strT);
//        }
//        for(;;)
//        {
//            String strT = in.nextLine();
//            if( strT.equals("")) break;
//            else
//                System.out.println(strT);
//        }
        //--Consolde
        Console cons = System.console();
        if(cons != null) {
            System.out.println(cons.readLine("username: "));
            char[] pwd = cons.readPassword("Pwd ");
            for (char i : pwd) System.out.print(i);
            System.out.println();
        }
        //--格式化输出
        System.out.printf("helle %s, i am %d years old\n",str1,34);

        System.out.printf( String.format("heall %s, i am %d yes\n", str1, 12));

        System.out.printf("%tc\n", new Date());
        System.out.printf("%1$s %2$tY-%2$tm-%2$td %2$tH:%2$tM:%2$tS\n", "data: ",new Date());
        System.out.printf("%s %tY-%<tm-%<td %<tH:%<tM:%<tS", "date: ", new Date());

//文件输入输出
        //--读入文件
        Scanner inFile = new Scanner(Paths.get("pwd.txt"),"UTF-8"); //import java.nio.file.Paths;
        //循环打印
        if(inFile != null)
        {
            while(inFile.hasNext())
            {
                System.out.println(inFile.next());
            }
        }
        inFile.close();
        //--写入文件 PrintWrite 操作和System.out
        FileWriter writer = new FileWriter("pwd1.txt");
        writer.write("hello writer!");


        String[] nums = new String[] {"a","b","c","d"};
        String[] nums1 = {"d","c","b","a"};
        for(String s : nums) System.out.println(s);
        System.out.println(Arrays.toString(nums1));
        Arrays.sort(nums1);
        System.out.println(Arrays.toString(nums1));

    }

}


class People{

    public People(String n, int a){
        this.name = n;
        this.age = a;
    }
    private int age;
    private String name;

    public  String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public void sayHello(String nam) {
        System.out.println("hello " + nam + " this is " + name );
    }

}
